package com.projecy.storehouse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.projecy.storehouse.entity.OutStorage;
import com.projecy.storehouse.entity.OutStorageDefault;
import com.projecy.storehouse.service.OutStorageDefaultService;
import com.projecy.storehouse.service.OutStorageService;
import com.projecy.storehouse.util.RepertoryResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * (OutStorage)表控制层
 *
 * @author maoyi
 * @since 2023-03-24 16:46:08
 */
@RestController
@RequestMapping("sys")
public class OutStorageController{

    @Autowired
    OutStorageService outStorageService;

    @Autowired
    OutStorageDefaultService outStorageDefaultService;

    /**
     * 入库申请
     */

    /**
     * 申请
     */

    /**
     * @GetMapping("/productFile/list3")
     * 库存：已分配
     */

    /**
     * 添加入库申请
     *
     * @param outStorage
     * @return
     */
    @PostMapping("/outStorage/add")
    public ResponseEntity<Object> insertOutStorage(@RequestBody OutStorageAndDefault outStorage){
        return outStorageService.insertOutStorage(outStorage.outStorage,outStorage.outStorageDefaults);
    }

    class OutStorageAndDefault{
        private OutStorage outStorage;
        private List<OutStorageDefault> outStorageDefaults;
    }


    /**
     * 复核
     */

    /**
     * 入库申请查询
     * @return
     */
    @GetMapping("/outStorage/list")
    public ResponseEntity<Object> seacherOutStorage(){
        return outStorageService.seacherOutStorage("待审核");
    }

    /**
     * 入库申请明细
     * @param putId
     * @return
     */
    @GetMapping("/outStorage/list1/{putId}")
    public ResponseEntity<Object> selectOneOutStorageDefault(@PathVariable long putId){
        return RepertoryResultUtil.success(true,outStorageDefaultService.list(new QueryWrapper<OutStorageDefault>().eq("put_id",putId)));
    }

    /**
     * 入库申请复核
     * @param putId
     * @return
     */
    /**
     * 通过
     * @param putId
     * @return
     */
    @PostMapping("/outStorage/check1/{putId}")
    public ResponseEntity<Object> checkOutStorageOk(@PathVariable Long putId){
        return RepertoryResultUtil.success(true,outStorageService.updateOutStorageMark(putId,"已审核"));
    }
    /**
     * 不通过
     * @param putId
     * @return
     */
    @PostMapping("/outStorage/check2/{putId}")
    public ResponseEntity<Object> checkOutStorage(@PathVariable Long putId){
        return RepertoryResultUtil.success(true,outStorageService.updateOutStorageMark(putId,"未通过"));
    }



    /**
     * 查询
     */

    /**
 * 入库申请查询(状态)
 * @param mark
 * @return
 */
    @GetMapping("/outStorage/list3/{mark}/{current}")
    public ResponseEntity<Object> seacherOutStorageMark(@PathVariable String mark){
        return RepertoryResultUtil.success(true,outStorageService.seacherOutStorageMark(mark));
    }

    /**
     *  @GetMapping("/outStorage/list1")
     */


}

